package Leetcode.tools;

public class ListNode {
    public int val;
    public ListNode next;
    public ListNode() {}
    public ListNode(int val) { this.val = val; }
    public ListNode(int val, ListNode next) { this.val = val; this.next = next; }

    public ListNode listBuilder(int[] nums){
        int n=nums.length;
        ListNode head = new ListNode(nums[0]);
        ListNode cur=head;
        for(int i=1;i<nums.length;i++){
            ListNode node = new ListNode(nums[i]);
            cur.next=node;
            cur=cur.next;
        }
        return head;
    }
    public void printAll(ListNode head){
        ListNode cur=head;
        while(cur!=null){
            System.out.print(cur.val);
            cur=cur.next;
        }
    }
}
